package caiziyou.com.designpattern.singleton.type7;

/**
 * 
 * 静态内部类
 * 静态内部类 不会和主类同时装载
 * 调用getInstance方法会导致内部类的装载，类装载是线程安全的
 * 推荐使用
 * @author Administrator
 *
 */
public class SingletonTest07 {
	public static void main(String[] args) {
		Singleton instance1 = Singleton.getInstance();
		Singleton instance2 = Singleton.getInstance();
		System.out.println(instance1 == instance2);
	}

}

class Singleton {

	private Singleton() {
	}

	private static class SingletonInstance {
		private static final Singleton INTANCE = new Singleton();
	}

	public static Singleton getInstance() {
		return SingletonInstance.INTANCE;
	}

}
